<?php

/**
 * Generate random string
 *
 * @package Rapide_Util
 */
class Rapide_Util_Random_String
{
	private $_sRandomString;

	/**
	 * Contruct generator using given characters
	 *
	 * @param string $sRandomString
	 */
	public function __construct($sRandomString = null)
	{
		if(isset($sRandomString))
			$this->_sRandomString = $sRandomString;
		else
			$this->_sRandomString = 'abcdefghijklmnopqrstuwqxyz0123456789';
	}

	/**
	 * Generate random string with given length
	 *
	 * @param int $iLength
	 * @return string
	 */
	public function generate($iLength = 9)
	{
		$sRandomName = '';

		for($i = 0; $i < $iLength; $i++)
		{
			$iRandomPosition = rand(0, strlen($this->_sRandomString) - 1);
			$sRandomName .= $this->_sRandomString[$iRandomPosition];
		}

		return $sRandomName;
	}
}

?>